// self defined type
#ifndef CALC_H
#define CALC_H

#define MAXTOKEN 128

typedef enum {
    T_NONE,
    T_ADD,
    T_SUB,
    T_MULTI,
    T_DIV,
    T_NUM,
    T_LP,	// (
    T_RP,	// )
    T_EOF
} TokenType;

typedef double calc_t;

typedef struct {
    TokenType type;
    char tkbuf[MAXTOKEN];
} TokenDesc, *Token;

typedef struct node {
    char type;
    calc_t value;
    struct node *left;
    struct node *right;
} Node, *Tree;

extern TokenDesc gtoken;
extern char inbuf[1024];
extern char *ic;

TokenType get_token(Token);

Tree parse_factor(void);
Tree parse_term(void);
Tree parse_expr(void);

calc_t eval_ast(Tree ast);
void free_ast(Tree ast);
#endif
